package com.gw.booking.controller.wechat;

import com.gw.booking.common.MessageCode;
import com.gw.booking.common.ResultObject;
import com.gw.booking.common.Util;
import com.gw.booking.dto.PageDto;
import com.gw.booking.dto.wechat.WLoginDtoOut;
import com.gw.booking.dto.wechat.WMerchantDetailDtoOut;
import com.gw.booking.dto.wechat.WMerchantListDtoOut;
import com.gw.booking.service.MerchantService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.lang.reflect.InvocationTargetException;

@Api(tags = {"微信-商家管理"})
@Controller
@RequestMapping("/wechat/merchant")
public class WMerchantController {
    @Autowired
    private MerchantService merchantService;

    @ApiOperation(value = "周围商家（30km）")
    @RequestMapping(value = "/list.do", method = {RequestMethod.GET})
    @ResponseBody
    public ResultObject<PageDto<WMerchantListDtoOut>> list(HttpServletRequest request
            , @ApiParam(value = "城市名称", required = true) @RequestParam String cityName
            , @ApiParam(value = "商家名称") @RequestParam(required = false) String shopName
            , @ApiParam(value = "商家分类id") @RequestParam(required = false) Integer merchantTypeId
            , @ApiParam(value = "纬度") @RequestParam(required = false) String latitude
            , @ApiParam(value = "经度") @RequestParam(required = false) String longitude
            , @ApiParam(value = "页数", required = true) @RequestParam int page
            , @ApiParam(value = "数量", required = true) @RequestParam int size)
            throws IllegalAccessException, NoSuchMethodException, InvocationTargetException {
        return new ResultObject(MessageCode.CODE_SUCCESS, merchantService.listForDiner(Util.getLoginToken(request), cityName, shopName, merchantTypeId, longitude, latitude, page, size));
    }

    @ApiOperation(value = "商家详情")
    @RequestMapping(value = "/deitail.do", method = {RequestMethod.GET})
    @ResponseBody
    public ResultObject<PageDto<WMerchantDetailDtoOut>> deitail(HttpServletRequest request
            , @ApiParam(value = "纬度", required = true) @RequestParam String latitude
            , @ApiParam(value = "经度", required = true) @RequestParam String longitude
            , @ApiParam(value = "商家id", required = true) @RequestParam Integer merchantId)
            throws IllegalAccessException, NoSuchMethodException, InvocationTargetException {
        return new ResultObject(MessageCode.CODE_SUCCESS, merchantService.detailForDiner(Util.getLoginToken(request), merchantId,longitude,latitude));
    }


}
